<template>
  <form @submit="formSubmit">
    <div class='depotMoveAdd'>
      <scroll-view scroll-y>
        <div class="detailList">
          <div class="weui-cells__title header">汽车信息</div>
          <div class="weui-cells weui-cells_after-title">
            <div class="weui-cell">
              <div class="weui-cell__bd">车架号</div>
              <div class="weui-cell__ft searchValue">
                    <div>{{GET_VIN}}</div>
                    <searchTriangle  s_value="车架号"  type='移库' :back="true"></searchTriangle>
              </div>
            </div>

            <div class="weui-cell">
              <div class="weui-cell__bd">汽车车型</div>
              <div class="weui-cell__ft">
                汽车车型汽车车型汽车车型汽车车型汽车车型汽车车型汽车车型汽车车型汽车车型汽车车型汽车车型
              </div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__bd">颜色</div>
              <div class="weui-cell__ft">
                颜色/颜色
              </div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__bd">原存放仓库</div>
              <div class="weui-cell__ft">
               原存放仓库
              </div>
            </div>
     
          </div>
        </div>

        <div class="detailList">
          <div class="weui-cells__title header">移库信息</div>
          <div class="weui-cells weui-cells_after-title">
            <div class="weui-cell">
              <div class="weui-cell__bd">移入仓库</div>
              <div class="weui-cell__ft">
                <picker class="weui-btn"  :disabled="editCode" name="indexPicker" @change="PickerChange" :value="data.indexPicker" :range="cangkuList">
                    <view class="weui-select weui-select_in-select-after noneBorder">{{ cangkuList[data.indexPicker] }}</view>
                </picker>
              </div>
            </div>

            <div class="weui-cell">
              <div class="weui-cell__bd">交接人</div>
              <div class="weui-cell__ft">
                <input maxlength="20"  :disabled="editCode" name="jiaojieren" :value="jiaojieren" placeholder="最多输入20字" />
              </div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__bd">备注</div>
              <div class="weui-cell__ft">
                <input maxlength="400"  :disabled="editCode" name="beizhu" :value="beizhu" placeholder="最多输入400字" />
              </div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__bd">图片</div>
              <div class="weui-cell__ft">
                <Qinniu></Qinniu>
              </div>
            </div>
          </div>
        </div>
        <view class="btn-area submit">
          <button formType="submit">提交</button>
        </view>
      </scroll-view>
    </div>
  </form>
</template>



<script>
  import detailList from '@/components/common/detailList'
  import Qinniu from '@/components/common/Qinniu'
  import searchTriangle from "@/components/common/searchTriangle"
  import {mapGetters,mapState} from "vuex";
  export default {
    data() {
      return {
        data: {
            indexPicker:"",//仓库地址的索引
            jiaojieren:"",
            beizhu:"",

        }, //数据源
        imagesArray: [], //照片
        cangkuList: [], //仓库地址
        editCode: true, //编辑，还会查看，亦或者是添加
      }
      
    },
    methods: {
      PickerChange(e) {
        this.data.indexPicker = e.mp.detail.value;
      },
      formSubmit: function (e) {
        const params = e.mp.detail.value

       // 传入表单数据，调用验证方法
        if (!this.WxValidate.checkForm(params)) {
            const error = this.WxValidate.errorList[0]
            this.WxValidate.showModal(error)
          return false
        }

         if(!this.GET_VIN){
            this.WxValidate.showModal({msg: '请选择车架号'})
            return false;
        }
        params.chejiaohao = this.GET_VIN ;

        if(this.imagesArray.length==0){
            this.WxValidate.showModal({msg: '请上传车龄照片'})
            return false;
        }


        

        this.$https.post("http://rap2api.taobao.org/app/mock/22254/lyl/xiaochegnxu/Warehousing_button_post",{params,img:this.imagesArray}).then(res=>{
                this.WxValidate.showModal({
                  msg: '提交成功',
                })
        })
      

      },
      // 判断disabled状态
      is_disabled() {
        let code = this.$mp.query.idCode
        switch (true) {
          case code == 1: //编辑
            this.editCode = false;
            break;
          case code == 2: //查看
            this.editCode = true;
            break;
          default:
            this.editCode = false;
            break; //添加
        }
      },
      
       initValidate() { 
        // 验证字段的规则
        const rules = {
          indexPicker:{
            required: true
          },
        }
        const message = {
              indexPicker:{
            required: "请选择仓库"
          },
    
        }

        //创建实例对象
        this.WxValidate = new this.wxValidate(rules,message);


      },
    },
    computed:{
      ...mapGetters(["GET_VIN"]),
    },
    mounted() {
      // console.dir("传递过来的id为"+this.$mp.query.id)
      this.initValidate();
      this.is_disabled();
      this.$https.get("http://rap2api.taobao.org/app/mock/22254/lyl/xiaochengxu/WarehousingDetail", {
        id: this.$mp.query.id
      }).then(res => {
        
        this.imagesArray = res.data.data.imgLIst;
        this.cangkuList = res.data.data.list

      }).catch(err => {
        console.dir(err)
      })
    },
    components: {
      detailList,
      Qinniu,
      searchTriangle
    },
  }
</script>


<style lang="scss" scoped>
  .depotMoveAdd {
    height: 100%;
    box-sizing: border-box;
    scroll-view {
      height: 100%;

    }

  }
</style>
